package com.proposition.exam.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.proposition.commons.exam.result.Result;
import com.proposition.commons.exam.result.ResultUtil;
import com.proposition.commons.exam.util.ExamAddUtil;
import com.proposition.commons.exam.util.ExamFieldVolidateUtil;
import com.proposition.commons.exam.util.ExamUtil;
import com.proposition.commons.model.ExamAnswer30;
import com.proposition.commons.model.ExamAnswer30Original;
import com.proposition.exam.mapper.ExamAnswer30Mapper;
import com.proposition.exam.service.ExamAnswer30Service;
import com.proposition.support.security.CurrentUser;
import com.proposition.support.utils.UUIDUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: 陈玉林
 * @modifiedBy:
 * @date: Create In 10:31 2017/11/3
 * @description:
 */
@Service
public class ExamAnswer30ServiceImpl extends ServiceImpl<ExamAnswer30Mapper, ExamAnswer30> implements ExamAnswer30Service {
    @Transactional
    @Override
    public Result add(String[] answer, Float[] answerScore, ExamAnswer30 exam, ExamAnswer30Original examOriginal) {
        String stem = ExamFieldVolidateUtil.getIllegalStem(exam.getStem());
        exam.setStem(stem);
        ExamAddUtil.volidateUniqueStem(exam);
        ExamUtil.volidateOutlineCode(exam.getOutlineCode());

        //验证题干
        String categoryStr = ExamUtil.getCategoryStr(exam.getCategoryId());
        String id = UUIDUtil.getExamUUIDByCategory(categoryStr);
        String userIdImport = CurrentUser.INSTANCE.getUserId();

        for (int i = 0; i < answer.length; i++) {
            switch (i + 1) {
                case 1:
                    exam.setAnswer1(answer[i]);
                    examOriginal.setAnswer1(answer[i]);
                    break;
                case 2:
                    exam.setAnswer2(answer[i]);
                    examOriginal.setAnswer2(answer[i]);
                    break;
                case 3:
                    exam.setAnswer3(answer[i]);
                    examOriginal.setAnswer3(answer[i]);
                    break;
                case 4:
                    exam.setAnswer4(answer[i]);
                    examOriginal.setAnswer4(answer[i]);
                    break;
                case 5:
                    exam.setAnswer5(answer[i]);
                    examOriginal.setAnswer5(answer[i]);
                    break;
                case 6:
                    exam.setAnswer6(answer[i]);
                    examOriginal.setAnswer6(answer[i]);
                    break;
                case 7:
                    exam.setAnswer7(answer[i]);
                    examOriginal.setAnswer7(answer[i]);
                    break;
                case 8:
                    exam.setAnswer8(answer[i]);
                    examOriginal.setAnswer8(answer[i]);
                    break;
                case 9:
                    exam.setAnswer9(answer[i]);
                    examOriginal.setAnswer9(answer[i]);
                    break;
                case 10:
                    exam.setAnswer10(answer[i]);
                    examOriginal.setAnswer10(answer[i]);
                    break;
                case 11:
                    exam.setAnswer11(answer[i]);
                    examOriginal.setAnswer11(answer[i]);
                    break;
                case 12:
                    exam.setAnswer12(answer[i]);
                    examOriginal.setAnswer12(answer[i]);
                    break;
                case 13:
                    exam.setAnswer13(answer[i]);
                    examOriginal.setAnswer13(answer[i]);
                    break;
                case 14:
                    exam.setAnswer14(answer[i]);
                    examOriginal.setAnswer14(answer[i]);
                    break;
                case 15:
                    exam.setAnswer15(answer[i]);
                    examOriginal.setAnswer15(answer[i]);
                    break;
                case 16:
                    exam.setAnswer16(answer[i]);
                    examOriginal.setAnswer16(answer[i]);
                    break;
                case 17:
                    exam.setAnswer17(answer[i]);
                    examOriginal.setAnswer17(answer[i]);
                    break;
                case 18:
                    exam.setAnswer18(answer[i]);
                    examOriginal.setAnswer18(answer[i]);
                    break;
                case 19:
                    exam.setAnswer19(answer[i]);
                    examOriginal.setAnswer19(answer[i]);
                    break;
                case 20:
                    exam.setAnswer20(answer[i]);
                    examOriginal.setAnswer20(answer[i]);
                    break;
                case 21:
                    exam.setAnswer21(answer[i]);
                    examOriginal.setAnswer21(answer[i]);
                    break;
                case 22:
                    exam.setAnswer22(answer[i]);
                    examOriginal.setAnswer22(answer[i]);
                    break;
                case 23:
                    exam.setAnswer23(answer[i]);
                    examOriginal.setAnswer23(answer[i]);
                    break;
                case 24:
                    exam.setAnswer24(answer[i]);
                    examOriginal.setAnswer24(answer[i]);
                    break;
                case 25:
                    exam.setAnswer25(answer[i]);
                    examOriginal.setAnswer25(answer[i]);
                    break;
                case 26:
                    exam.setAnswer26(answer[i]);
                    examOriginal.setAnswer26(answer[i]);
                    break;
                case 27:
                    exam.setAnswer27(answer[i]);
                    examOriginal.setAnswer27(answer[i]);
                    break;
                case 28:
                    exam.setAnswer28(answer[i]);
                    examOriginal.setAnswer28(answer[i]);
                    break;
                case 29:
                    exam.setAnswer29(answer[i]);
                    examOriginal.setAnswer29(answer[i]);
                    break;
                case 30:
                    exam.setAnswer30(answer[i]);
                    examOriginal.setAnswer30(answer[i]);
                    break;

                default:
                    break;
            }
        }
        for (int i = 0; i < answerScore.length; i++) {
            switch (i + 1) {
                case 1:
                    exam.setAnswer1Score(answerScore[i]);
                    examOriginal.setAnswer1Score(answerScore[i]);
                    break;
                case 2:
                    exam.setAnswer2Score(answerScore[i]);
                    examOriginal.setAnswer2Score(answerScore[i]);
                    break;
                case 3:
                    exam.setAnswer3Score(answerScore[i]);
                    examOriginal.setAnswer3Score(answerScore[i]);
                    break;
                case 4:
                    exam.setAnswer4Score(answerScore[i]);
                    examOriginal.setAnswer4Score(answerScore[i]);
                    break;
                case 5:
                    exam.setAnswer5Score(answerScore[i]);
                    examOriginal.setAnswer5Score(answerScore[i]);
                    break;
                case 6:
                    exam.setAnswer6Score(answerScore[i]);
                    examOriginal.setAnswer6Score(answerScore[i]);
                    break;
                case 7:
                    exam.setAnswer7Score(answerScore[i]);
                    examOriginal.setAnswer7Score(answerScore[i]);
                    break;
                case 8:
                    exam.setAnswer8Score(answerScore[i]);
                    examOriginal.setAnswer8Score(answerScore[i]);
                    break;
                case 9:
                    exam.setAnswer9Score(answerScore[i]);
                    examOriginal.setAnswer9Score(answerScore[i]);
                    break;
                case 10:
                    exam.setAnswer10Score(answerScore[i]);
                    examOriginal.setAnswer10Score(answerScore[i]);
                    break;
                case 11:
                    exam.setAnswer11Score(answerScore[i]);
                    examOriginal.setAnswer11Score(answerScore[i]);
                    break;
                case 12:
                    exam.setAnswer12Score(answerScore[i]);
                    examOriginal.setAnswer12Score(answerScore[i]);
                    break;
                case 13:
                    exam.setAnswer13Score(answerScore[i]);
                    examOriginal.setAnswer13Score(answerScore[i]);
                    break;
                case 14:
                    exam.setAnswer14Score(answerScore[i]);
                    examOriginal.setAnswer14Score(answerScore[i]);
                    break;
                case 15:
                    exam.setAnswer15Score(answerScore[i]);
                    examOriginal.setAnswer15Score(answerScore[i]);
                    break;
                case 16:
                    exam.setAnswer16Score(answerScore[i]);
                    examOriginal.setAnswer16Score(answerScore[i]);
                    break;
                case 17:
                    exam.setAnswer17Score(answerScore[i]);
                    examOriginal.setAnswer17Score(answerScore[i]);
                    break;
                case 18:
                    exam.setAnswer18Score(answerScore[i]);
                    examOriginal.setAnswer18Score(answerScore[i]);
                    break;
                case 19:
                    exam.setAnswer19Score(answerScore[i]);
                    examOriginal.setAnswer19Score(answerScore[i]);
                    break;
                case 20:
                    exam.setAnswer20Score(answerScore[i]);
                    examOriginal.setAnswer20Score(answerScore[i]);
                    break;
                case 21:
                    exam.setAnswer21Score(answerScore[i]);
                    examOriginal.setAnswer21Score(answerScore[i]);
                    break;
                case 22:
                    exam.setAnswer22Score(answerScore[i]);
                    examOriginal.setAnswer22Score(answerScore[i]);
                    break;
                case 23:
                    exam.setAnswer23Score(answerScore[i]);
                    examOriginal.setAnswer23Score(answerScore[i]);
                    break;
                case 24:
                    exam.setAnswer24Score(answerScore[i]);
                    examOriginal.setAnswer24Score(answerScore[i]);
                    break;
                case 25:
                    exam.setAnswer25Score(answerScore[i]);
                    examOriginal.setAnswer25Score(answerScore[i]);
                    break;
                case 26:
                    exam.setAnswer26Score(answerScore[i]);
                    examOriginal.setAnswer26Score(answerScore[i]);
                    break;
                case 27:
                    exam.setAnswer27Score(answerScore[i]);
                    examOriginal.setAnswer27Score(answerScore[i]);
                    break;
                case 28:
                    exam.setAnswer28Score(answerScore[i]);
                    examOriginal.setAnswer28Score(answerScore[i]);
                    break;
                case 29:
                    exam.setAnswer29Score(answerScore[i]);
                    examOriginal.setAnswer29Score(answerScore[i]);
                    break;
                case 30:
                    exam.setAnswer30Score(answerScore[i]);
                    examOriginal.setAnswer30Score(answerScore[i]);
                    break;

                default:
                    break;
            }
        }


        exam.setId(id);//设置id
        exam.setUserIdImport(userIdImport);//设置当前导入用户id
        exam.insert();

        examOriginal.setId(id);
        examOriginal.setUserIdImport(userIdImport);
        examOriginal.insert();
        return ResultUtil.sucess();
    }
}
